package com.atguigu2.two;

/**
 * ClassName: TwoArrayTest
 * Package: com.atguigu2.two
 * Description:
 *
 * @Author 姜
 * @Create 2023/11/14 13:40
 * @Version 1.0
 */
public class TwoArrayTest {
    public static void main(String[] args) {
        // 1. 数组的声明与初始化
        // 方式1：静态初始化:数组变量的赋值和数组元素的赋值同时进行
        int[][] arr2 = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        // 方式2：动态初始化：数组变量的赋值和数组元素的赋值分开进行
        String[][] arr3 = new String[3][4];

        double[][] arr4 = new double[2][];

        int arr5[][] = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        int[] arr6[] = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        int arr7[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        String arr8[][] = new String[3][4];
        // 2. 数组元素的调用
        // 针对于arr2来说，外层元素{1,2,3},{4,5,6},{7,8,9} 内层元素：1,2,3,4,5,6,7,8,9
        // 调用内层元素
        System.out.println(arr2[0][0]); // 1
        System.out.println(arr2[2][0]); // 7

        // 调用外层元素
        System.out.println(arr2[0]); // [I@4eec7777

        // 测试arr3、arr4
        arr3[0][1] = "Tom";
        System.out.println(arr3[0][1]); // Tom
        System.out.println(arr3[0]); // [Ljava.lang.String;@3b07d329

        arr4[0] = new double[4];
        arr4[0][0] = 1.0;
        System.out.println(arr4[0][0]);

        // 3. 数组的长度
        System.out.println(arr2.length);
        System.out.println(arr2[0].length);
        // 4. 如何遍历数组
        for (int i = 0; i < arr2.length; i++) {
            for (int j = 0; j < arr2[i].length; j++) {
                System.out.print(arr2[i][j]+"\t");
            }
            System.out.println();
        }
    }
}
